package youdao;

import com.google.common.collect.Maps;
import com.google.common.io.Resources;

import java.io.BufferedInputStream;
import java.util.Map;
import java.util.Properties;

/**
 * @author ydy
 * @version 2017/12/13  11:23
 */
public class ReadProperties {
    public static Map<String,Object> readFile(String args) {
        Properties prop = new Properties();
        Map<String,Object> map = Maps.newHashMap();
        try{
            BufferedInputStream bufferedInputStream = (BufferedInputStream) Resources.getResource("youdao.properties").getContent();
            byte[] bs = new byte[1024];
            while (bufferedInputStream.read(bs) != -1) {
                System.out.println(new String(bs));
                if (bs.toString().contains("=")) {
                    String[] split = bs.toString().split("=");
                    map.put(split[0], split[1]);
                }
            }
            //读取属性文件a.properties
//            InputStream in = null;
//                File file = new File("./"+args+".properties");
//                in = new BufferedReader(file);
//                prop.load(in);     ///加载属性列表
//                Iterator<String> it=prop.stringPropertyNames().iterator();
//                while(it.hasNext()){
//                    String key=it.next();
//                    map.put(key,prop.getProperty(key));
//                    System.out.println(key+":"+prop.getProperty(key));
//                }
//            in.close();
//            ///保存属性到b.properties文件
//            FileOutputStream oFile = new FileOutputStream("b.properties", true);//true表示追加打开
//            prop.setProperty("phone", "10086");
//            prop.store(oFile, "The New properties file");
//            oFile.close();
        }
        catch(Exception e){
            System.out.println(e);
        }
        return map;
    }
}
